﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Xml;
using com.lover.astd.common.config;
using com.lover.astd.common.model;
using com.lover.astd.common;

namespace com.lover.astd.game.ui.server.impl.equipment
{
    public class MerchantServer : LogicServer
    {
        /// <summary>
        /// 委派商人
        /// </summary>
        public MerchantServer(MainForm frm) { _mainForm = frm; ServerName = ConfigStrings.S_Merchant; ServerReadableName = ConfigStrings.SR_Merchant; }
        public override void renderSettings()
        {
            MainForm frm = _mainForm;
            Dictionary<string, string> conf = getConfig(ServerName);
            frm.chk_merchant.Checked = conf.ContainsKey(ConfigStrings.enabled) && conf[ConfigStrings.enabled].ToLower().Equals("true");

            if(conf.ContainsKey(ConfigStrings.type)) frm.combo_merchant_type.SelectedItem = conf[ConfigStrings.type];

            frm.chk_merchant_onlyfree.Checked = conf.ContainsKey(ConfigStrings.only_free) && conf[ConfigStrings.only_free].ToLower().Equals("true");

            if (conf.ContainsKey(ConfigStrings.sell_quality)) frm.combo_merchant_sell_level.SelectedItem = conf[ConfigStrings.sell_quality];
        }
        public override void saveSettings()
        {
            MainForm frm = _mainForm;
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, frm.chk_merchant.Checked.ToString());
            if (frm.combo_merchant_type.SelectedItem != null)
                conf.setConfig(ServerName, ConfigStrings.type, frm.combo_merchant_type.SelectedItem.ToString());
            else
                conf.setConfig(ServerName, ConfigStrings.type, "马");
            conf.setConfig(ServerName, ConfigStrings.only_free, frm.chk_merchant_onlyfree.Checked.ToString());
            if (frm.combo_merchant_sell_level.SelectedItem != null)
                conf.setConfig(ServerName, ConfigStrings.sell_quality, frm.combo_merchant_sell_level.SelectedItem.ToString());
            else
                conf.setConfig(ServerName, ConfigStrings.sell_quality, "蓝色");
        }
        public override void loadDefaultSettings()
        {
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, "true");
            conf.setConfig(ServerName, ConfigStrings.type, "马");
            conf.setConfig(ServerName, ConfigStrings.only_free, "true");
            conf.setConfig(ServerName, ConfigStrings.sell_quality, "红色");
            renderSettings();
        }
        
    }
}
